package cn.gson.springboot.controller;


import cn.gson.springboot.model.pojos.Complain;
import cn.gson.springboot.model.pojos.Employee;

import cn.gson.springboot.model.service.ComplainService;
import cn.gson.springboot.model.service.QaService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ComplainController {
    @Autowired
    ComplainService complainService;

    @RequestMapping("/complain-list")
    @ResponseBody
    public Map<String,Object> complainList(Integer page,Integer size, String search,Integer type) {
         Page<Object> obj = PageHelper.startPage(page, size);
        List<Complain> complains = complainService.selectAll(search,type);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());//返回总页数
        map.put("rows",complains);//返回查到的数据
        return map;
    }
    @RequestMapping("/complain-type-list")
    @ResponseBody
    public List<Complain> complainList() {
        List<Complain> complains = complainService.selectComplainType();
        return complains;
    }

    @RequestMapping("/complain-deleteOne")
    @ResponseBody
    public void deleteOne() {
        complainService.deleteOne(2);
    }

    /*@RequestMapping("/complain-selectOne")
    @ResponseBody
    public Complain selectOne() {
        Complain complain = complainService.selectOne(2);
        return complain;
    }
*/
    @RequestMapping("/complain-alter")
    @ResponseBody
    public void alter() {
        Complain complain = new Complain();
        complain.setComplainTheme("衣服有污渍");
        complainService.alter(1,complain);

    }

    @RequestMapping("/complain-addComplain")
    @ResponseBody
    public void addComplain(@RequestBody Complain complain) {
        System.out.println(complain);
        complainService.addComplain(complain);
    }
}